package jp.co.toshiba.ffsa.action.cstp;

import javax.annotation.Resource;

import jp.co.toshiba.ffsa.action.common.CommonAction;
import jp.co.toshiba.ffsa.entity.Information;
import jp.co.toshiba.ffsa.form.cstp.Cstp102Form;
import jp.co.toshiba.ffsa.service.cstp.Cstp102Service;

import org.seasar.struts.annotation.ActionForm;
import org.seasar.struts.annotation.Execute;
import org.seasar.struts.util.RequestUtil;

/**
 * @author npc
 */
public class Cstp102Action extends CommonAction{

    /** 画面ID */
    public String screenID = "CSTP102";

    @ActionForm
    @Resource
    protected Cstp102Form cstp102Form;

    @Resource
    protected Cstp102Service cstp102Service;

    /**
     * 初期処理
     * @return 画面遷移先
     */
    @Execute(validator = false)
    public String index() throws Exception {
        try{
            // リファラ判定
            if(this.judgeRefferer()){
                // お知らせ詳細情報取得
                information();
            return "/cstp/cstp102.jsp";

            }else{
                return this.topTransition;
            }
        }catch(Exception e){
            this.errorLogWriter(e, "index", this.screenID);
            throw e;
        }
    }

    /**
     * お知らせ詳細情報取得
     * @return
     * @throws Exception
     */
    @Execute(validator = true, input="/cstp/cstp102/error")
    private String information() throws Exception{
        // リファラ判定
        if(this.judgeRefferer()){

            // お知らせIDで詳細情報取得
            String informationId = RequestUtil.getRequest().getParameter("informationId");
            Information information = cstp102Service.getInformationBySubject(informationId);

            this.cstp102Form.setSubject(information.subject);
            this.cstp102Form.setBody(information.body);

            return "/cstp/cstp102.jsp";

        }else{
            return this.topTransition;
        }
    }

    /**
     * バリデーションエラー処理
     * @return 遷移先
     * @throws Exception
     */
    @Execute(validator=false)
    public String error() throws Exception{
        // リファラ判定
        if(this.judgeRefferer()){
            return index();
        }else{
            return this.topTransition;
        }
    }
}